#include<iostream>
#include<vector>
class Solution {
public:
    std::vector<int> constructArr(std::vector<int>& a) {
        /*std::vector<int> nums;
        nums.resize(a.size(), 0);
        std::vector<int> left, right;
        left.resize(a.size(), 1);
        right.resize(a.size(), 1);
        for (int i = 1; i < static_cast<int>(a.size()); ++i)
            left[i] = a[i - 1] * left[i - 1];
        for (int i = static_cast<int>(a.size() - 2); i >= 0; --i)
            right[i] = a[i + 1] * right[i + 1];
        for (int i = 0; i < static_cast<int>(a.size()); ++i)
            nums[i] = left[i] * right[i];
        return nums;*/
        int len = a.size();
        if (len == 0) 
            return {};
        std::vector<int> b(len, 1);
        b[0] = 1;
        int tmp = 1;
        for (int i = 1; i < len; i++)
            b[i] = b[i - 1] * a[i - 1];
        for (int i = len - 2; i >= 0; i--)
        {
            tmp *= a[i + 1];
            b[i] *= tmp;
        }
        return b;
    }
};
int main()
{
    std::vector<int> nums{ 1, 2, 3, 4, 5 };
    std::vector<int> retnums = Solution().constructArr(nums);
    for (const auto& num : retnums)
        std::cout << num << " ";
    std::cout << std::endl;
    return 0;
}